home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / egs.lha / EGS / EGS_Devels / Examples / Other / Eyes.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  6KB  |  297 lines

  1.  
  2. /**
  3.  **  Author: D.H. / U.S.
  4.  **  Last Change     : 14. Juli 1992 mvk
  5.  **                    SAS adaption
  6.  **                    17 Dec 1992   mvk
  7.  **
  8.  **  Description:
  9.  **                Eyes looking at the mouse pointer
  10.  **
  11.  **  (C) by VIONA Development 1991,1992,1993
  12.  **
  13.  **/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #include <exec/types.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21.  
  22. #include <egs/egs.h>
  23. #include <egs/egsintuigfx.h>
  24. #include <egs/egsintui.h>
  25. #include <egs/egslayers.h>
  26. #include <egs/egsgfx.h>
  27.  
  28. #include <egs/proto/egs.h>
  29. #include <egs/proto/egslayers.h>
  30. #include <egs/proto/egsgfx.h>
  31. #include <egs/proto/egsintui.h>
  32.  
  33.  
  34. struct EI_NewWindow newWindow =
  35. {
  36.   200, 0, 300, 150,
  37.   300, 150, 300, 150,
  38.   NULL,
  39.   EI_WINDOWCLOSE+EI_WINDOWBACK+EI_WINDOWDRAG,
  40.   NULL,                                      /* GadgetPtr */
  41.   "Eyes",
  42.   EI_SIMPLE_REFRESH,
  43.   EI_iCLOSEWINDOW+EI_iREFRESHWINDOW
  44.   /* ... anyway */
  45.   };
  46.  
  47.  
  48.  
  49. EI_WindowPtr win;
  50. EG_RastPortPtr rast;
  51. E_EBitMapPtr ras;
  52. struct EG_AreaInfo info;
  53. EG_Polygon buffer[40];
  54. WORD midX, midY;
  55. WORD radius;
  56. WORD prad;
  57. WORD rmax, xmax, ymax;
  58.  
  59. struct Library  *EGSIntuiBase,*EGSGfxBase,*EGSLayersBase,*EGSBase;
  60.  
  61.  
  62. void DrawEyes (void)
  63. {
  64.   rast->APen = win->WinColors.Dark;
  65.  
  66.   EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-4));
  67.  
  68.   EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-4));
  69.  
  70.   rast->APen = win->WinColors.Light;
  71.  
  72.   EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-6));
  73.  
  74.   EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-6));
  75. }
  76.  
  77.  
  78.  
  79. void DrawPupill (WORD x, WORD y)
  80. {
  81.   rast->APen = win->WinColors.Dark;
  82.   EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
  83.  
  84.   rast->APen = win->WinColors.Light;
  85.  
  86.   EG_AreaCircle (rast, (WORD)(x-prad / 2), (WORD)(y-prad / 2), (WORD)(prad / 4));
  87.  
  88. }
  89.  
  90.  
  91.  
  92. void RedrawPupill (WORD x, WORD y)
  93. {
  94.   rast->APen = win->WinColors.Light;
  95.   EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
  96. }
  97.  
  98.  
  99.  
  100. WORD py1, py2, px1, px2;
  101. WORD oy1, oy2, ox1, ox2;
  102. WORD oldX, oldY;
  103.  
  104.  
  105.  
  106. WORD SQR (LONG x)
  107. {
  108.   WORD h1, h2, h3;
  109.  
  110.   if ((x<0) || (x>2000*2000))
  111.     x = 1;
  112.   h1 = 1;
  113.   h2 = x / 2;
  114.   while ((h1*h1>x) || (h1+1)*(h1+1)<x)
  115.     {
  116.     h3 = (h1+h2) / 2;
  117.     h2 = h1;
  118.     h1 = x / h3;    /* oder h3 / x ??? */
  119.     }
  120.   return h1;
  121. }
  122.  
  123.  
  124.  
  125. void CalcPupills (WORD dx, WORD dy)
  126. {
  127.   py1 = midY + ( (dy*(radius-prad-6)) / rmax);
  128.   px1 = midX + ( ((dx+radius)*(radius-prad-6)) / rmax) - radius;
  129.   py2 = midY + ( (dy*(radius-prad-6)) / rmax);
  130.   px2 = midX + ( ((dx-radius)*(radius-prad-6)) / rmax) + radius;
  131. }
  132.  
  133.  
  134.  
  135. void RedrawPupills (void)
  136. {
  137.   if ((oldX!=win->WScreen->EScreen->MouseX) ||
  138.      (oldY!=win->WScreen->EScreen->MouseY))
  139.     {
  140.  
  141.     oldX = win->WScreen->EScreen->MouseX;
  142.     oldY = win->WScreen->EScreen->MouseY;
  143.  
  144.     CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
  145.  
  146.     EL_LockLayer (win->WLayer);
  147.     E_MouseOff (win->WScreen->EScreen);
  148.  
  149.     RedrawPupill (ox1, oy1);
  150.     DrawPupill (px1, py1);
  151.  
  152.     ox1 = px1;
  153.     oy1 = py1;
  154.  
  155.     RedrawPupill (ox2, oy2);
  156.     DrawPupill (px2, py2);
  157.  
  158.     ox2 = px2;
  159.     oy2 = py2;
  160.  
  161.     E_MouseOn (win->WScreen->EScreen);
  162.     EL_UnlockLayer (win->WLayer);
  163.     }
  164. }
  165.  
  166.  
  167.  
  168. void ReDraw (void)
  169. {
  170.   DrawEyes ();
  171.   DrawPupill (px1, py1);   ox1 = px1;   oy1 = py1;
  172.   DrawPupill (px2, py2);   ox2 = px2;   oy2 = py2;
  173. }
  174.  
  175.  
  176.  
  177. void Crash (char *string)
  178. {
  179.   if (win!=NULL)
  180.     {
  181.     EI_CloseWindow (win);
  182.     win = NULL;
  183.     }
  184.   if (ras!=NULL)
  185.     E_DisposeBitMap (ras);
  186.  
  187.   if (EGSIntuiBase)
  188.     CloseLibrary (EGSIntuiBase);
  189.  
  190.   if (EGSGfxBase)
  191.     CloseLibrary (EGSGfxBase);
  192.  
  193.   if (EGSLayersBase)
  194.     CloseLibrary (EGSLayersBase);
  195.  
  196.   if (EGSBase)
  197.     CloseLibrary (EGSBase);
  198.  
  199.   if (string != NULL)
  200.     {
  201.     printf ("%s\n", string);
  202.     exit (20L);
  203.     }
  204.   exit (0L);
  205. }
  206.  
  207.  
  208.  
  209. EI_EIntuiMsgPtr msg;
  210. BOOL done;
  211. extern float sqrt (float f);
  212.  
  213. void main (void)
  214. {
  215.   /* Öffne die Bibliotheken */
  216.  
  217.   EGSBase = (APTR) OpenLibrary ("egs.library", 0);
  218.   if (NULL == EGSBase)
  219.     Crash ("Can't open EGS.library ");
  220.  
  221.   EGSIntuiBase = (APTR) OpenLibrary ("egsintui.library", 0);
  222.   if (NULL == EGSIntuiBase)
  223.     Crash ("Can't open EGSIntui.library ");
  224.  
  225.   EGSGfxBase = (APTR) OpenLibrary ("egsgfx.library", 0);
  226.   if (NULL == EGSGfxBase)
  227.     Crash ("Can't open EGSGfx.library ");
  228.  
  229.   EGSLayersBase = (APTR) OpenLibrary ("egslayers.library", 0);
  230.   if (NULL == EGSLayersBase)
  231.     Crash ("Can't open EGSLayers.library ");
  232.  
  233.   win = NULL;
  234.  
  235.   win = EI_OpenWindow (&newWindow);
  236.  
  237.   if (win == NULL)
  238.     Crash ("Can't open window !");
  239.  
  240.   rast = win->RPort;
  241.   midX = win->BorderLeft + win->Width / 2;
  242.   midY = win->BorderTop + win->Height / 2;
  243.   radius = win->Height / 2;
  244.   prad = (radius*2) / 5;
  245.  
  246.   rmax = (WORD) (sqrt( (float) (( (win->WScreen->Width-radius)*
  247.                                 (win->WScreen->Width-radius)) +
  248.                                 ((win->WScreen->Height-radius)*
  249.                                 (win->WScreen->Height-radius) )) ) );
  250.  
  251.   ras = E_AllocBitMap (win->Width, win->Height, (UWORD)1, 0, 0,
  252.                                    win->WScreen->EScreen->Map);
  253.   if (ras == NULL)
  254.     Crash ("Can't get mem for EBitMap ");
  255.   else
  256.     {
  257.     rast->TmpRas = ras;
  258.     rast->AreaInfo = EG_InitArea (&info, &buffer[0], (WORD)500);
  259.  
  260.     oldX = win->WScreen->EScreen->MouseX;
  261.     oldY = win->WScreen->EScreen->MouseY;
  262.  
  263.     CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
  264.  
  265.     ReDraw ();
  266.     done = FALSE;
  267.     do {
  268.       Delay (10);
  269.       msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
  270.           while (msg!=NULL)
  271.           {
  272.  
  273.                if (EI_iREFRESHWINDOW & msg->Class)
  274.                {
  275.                    if (EI_BeginRefresh (win, (LONG)msg->IAddress))
  276.                       {
  277.                             ReDraw ();
  278.                             EI_EndRefresh (win, TRUE);
  279.                       }
  280.                }
  281.  
  282.                if (EI_iCLOSEWINDOW & msg->Class)
  283.                done = TRUE;
  284.  
  285.                 ReplyMsg ((struct Message *)msg);
  286.                 msg = (EI_EIntuiMsgPtr) GetMsg (win->UserPort);
  287.           }
  288.       RedrawPupills ();
  289.  
  290.       } while (! done);
  291.     }
  292.  
  293.   /* THE END */
  294.   Crash (NULL);
  295. }
  296.  
  297.